import { Exclude } from 'class-transformer';
import { SysRole } from '../../roles/entities/role.entity';
import {
  Column,
  CreateDateColumn,
  Entity,
  ManyToMany,
  PrimaryGeneratedColumn,
  UpdateDateColumn,
} from 'typeorm';

@Entity('sys_menu', { schema: 'lzo_admin_nestjs' })
export class SysMenu {
  @PrimaryGeneratedColumn({ type: 'bigint', name: 'id', comment: 'ID' })
  id: string;

  @Column('bigint', { name: 'parent_id', comment: '父菜单ID' })
  parentId: string;

  @Column('varchar', {
    name: 'tree_path',
    nullable: true,
    comment: '父节点ID路径',
    length: 255,
  })
  treePath: string | null;

  @Column('varchar', { name: 'name', comment: '菜单名称', length: 64 })
  name: string;

  @Column('tinyint', {
    name: 'type',
    comment: '菜单类型（1-菜单 2-目录 3-外链 4-按钮）',
  })
  type: number;

  @Column('varchar', {
    name: 'route_name',
    nullable: true,
    comment: '路由名称（Vue Router 中用于命名路由）',
    length: 255,
  })
  routeName: string | null;

  @Column('varchar', {
    name: 'route_path',
    nullable: true,
    comment: '路由路径（Vue Router 中定义的 URL 路径）',
    length: 128,
  })
  routePath: string | null;

  @Column('varchar', {
    name: 'component',
    nullable: true,
    comment: '组件路径（组件页面完整路径，相对于 src/views/，缺省后缀 .vue）',
    length: 128,
  })
  component: string | null;

  @Column('varchar', {
    name: 'perm',
    nullable: true,
    comment: '【按钮】权限标识',
    length: 128,
  })
  perm: string | null;

  @Column('tinyint', {
    name: 'always_show',
    nullable: true,
    comment: '【目录】只有一个子路由是否始终显示（1-是 0-否）',
    default: () => "'0'",
  })
  alwaysShow: number | null;

  @Column('tinyint', {
    name: 'keep_alive',
    nullable: true,
    comment: '【菜单】是否开启页面缓存（1-是 0-否）',
    default: () => "'0'",
  })
  keepAlive: number | null;

  @Column('int', {
    name: 'visible',
    nullable: true,
    comment: '显示状态（1-显示 0-隐藏）',
    default: () => "'1'",
  })
  visible: number | null;

  @Column('int', {
    name: 'sort',
    nullable: true,
    comment: '排序',
    default: () => "'0'",
  })
  sort: number | null;

  @Column('varchar', {
    name: 'icon',
    nullable: true,
    comment: '菜单图标',
    length: 64,
  })
  icon: string | null;

  @Column('varchar', {
    name: 'redirect',
    nullable: true,
    comment: '跳转路径',
    length: 128,
  })
  redirect: string | null;

  @CreateDateColumn({
    name: 'create_time',
    nullable: true,
    comment: '创建时间',
  })
  @Exclude()
  createTime: Date | null;

  @UpdateDateColumn({
    name: 'update_time',
    nullable: true,
    comment: '更新时间',
  })
  @Exclude()
  updateTime: Date | null;

  @Column('varchar', {
    name: 'params',
    nullable: true,
    comment: '路由参数',
    length: 255,
  })
  params: string | null;

  @ManyToMany(() => SysRole, (sysRole) => sysRole.sysMenus, {
    nullable: true,
  })
  sysRoles: SysRole[];
}
